package com.cnwow.status;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.SimpleAdapter;

public class MySimpleAdapter extends SimpleAdapter {

	public MySimpleAdapter(Context context,
			List<? extends Map<String, ?>> data, int resource, String[] from,
			int[] to) {
		super(context, data, resource, from, to);
	}
	
	@Override
	public void setViewImage(ImageView v, String value) {

		// server status(up): 服务器状态(工作)
		if (value.toLowerCase().equals("up")) {
			setViewImage(v, R.drawable.server_up);
		}
		// server status(down):服务器状态(宕机)
		else if (value.toLowerCase().equals("down")) {
			setViewImage(v, R.drawable.server_down);
		}
		// server load(high):服务器负载(满)
		else if (value.toLowerCase().equals("high")) {
			setViewImage(v, R.drawable.serverload_full);
		}
		// server load(medium):服务器负载(拥挤)
		else if (value.toLowerCase().equals("medium")) {
			setViewImage(v, R.drawable.serverload_busy);
		}
		// server load(low):服务器负载(正常)
		else if (value.toLowerCase().equals("low")) {
			setViewImage(v, R.drawable.serverload_normal);
		} else {
			super.setViewImage(v, value);
		}
		// server load():负载异常
	}

	// 设置颜色
	private String[] colors = new String[] { "#D4C9A0", "#F5F0CA" };

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = super.getView(position, convertView, parent);
		int colorPos = position % 2;
		view.setBackgroundColor(Color.parseColor(colors[colorPos]));
		return view;
	}

}
